home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0031_Filesize & ZeroByte Files.pas < prev    next >
Pascal/Delphi Source File  |  1993-09-26  |  3KB  |  56 lines

  1. (*
  2. From: DAVIDDANIEL ANDERSON         Refer#: 2239
  3. Subj: FileSize in DOS                Conf: (232) T_Pascal_R
  4.  
  5. The FileSize "returns the number of components" in a file.  Thus, it
  6. may not work as you might assume on untyped files, or files of records.
  7.  
  8. The file should be declared as a file of byte or char or as a text
  9. file, in order to use FileSize.
  10.  
  11. An alternative to FileSize is to use the SearchRec type in the DOS
  12. unit.  This program deletes a file if it is 0 bytes.  The filespec is
  13. provided by the user on the command line, and can contain wildcards.
  14. *)
  15.  
  16. PROGRAM delete_0_byte_files;
  17. USES Dos;
  18. VAR
  19.    MaybeZero   : File of Byte;   { the file in question }
  20.    DirInfo     : SearchRec;      { a record of the file }
  21.    FMask       : PathStr;        { entire path as specified by user }
  22.    MZName      : PathStr;        { path of file in question }
  23.    FDir        : DirStr;         { dir of file in question }
  24.    FName       : NameStr;        { name of file in question }
  25.    FExt        : ExtStr;         { ext of file in question }
  26.    NZero       : Word;           { number of files deleted }
  27.  
  28. BEGIN
  29.      NZero := 0;
  30.      IF ParamCount = 1 THEN
  31.         FMask := ParamStr(1)     { use command line info, if it exists }
  32.      ELSE BEGIN
  33.         Writeln('You must specify a file_mask, such as "*.*"!');
  34.         Halt;
  35.      END;
  36.      FSplit(FExpand(FMask),FDir,FName,FExt);  { split cmdlind info into }
  37.      IF (FName = '') THEN                       { components }
  38.         FMask := FMask + '*.*';          { if only a DOS path was specified, }
  39.      FindFirst(FMask, Archive, DirInfo);    { append a wildcard spec }
  40.  
  41.      WHILE DosError = 0 DO               { check every valid file for size }
  42.      BEGIN                               { append path to name, to allow }
  43.           MZName := FDir+DirInfo.Name;  { paths and drives other than current }
  44.           Assign(MaybeZero,MZName);    { use Assign since Erase can only work }
  45.                                              { on *files*, -not- file names }
  46.           IF (DirInfo.Size = 0) THEN BEGIN  { THE MEAT! use the SearchRec }
  47.              Writeln('Deleting ',MZName);     { for determining file size }
  48.              Erase(MaybeZero);             { give a message and delete it }
  49.              NZero := NZero + 1;           { incremented counter, of course }
  50.           END;
  51.  
  52.           FindNext(DirInfo);               { look for another matching file }
  53.      END;
  54.      Writeln('Files Deleted: ',NZero);     { simply display total # deleted }
  55. END.
  56.